package com.cgs.query.monitor

import com.cgs.query.metrics.SERVER_POOL_NAME
import com.cgs.query.monitor.metrics.*
import mu.KotlinLogging
import org.springframework.beans.factory.annotation.Autowired

private val logger = KotlinLogging.logger { }

/**
 * 监控项目
 */
class ServerMonitor : MonitorBean<ServerMonitorObj, ServerMonitorInfo> {

    @Autowired
    private lateinit var dataSourceMonitor: DataSourceMonitor

    override fun start() {
        logger.info { ">>>>>>>>>>>>>>>>系统自监控" }
    }

    override fun stop() {
        logger.info { ">>>>>>>>>>>>>>>>系统自监控" }
    }

    override fun monitor(obj: ServerMonitorObj): ServerMonitorInfo? {
        val timerInfoList = MetricsHelper.INSTANCE.getServerTimer()
        val meterInfoList = CodahaleMetricsHelper.INSTANCE.getServerMeterInfo()
        val sourceMonitorInfo = dataSourceMonitor.monitor(SourceMonitorObj((SERVER_POOL_NAME)))
        return ServerMonitorInfo(timerInfoList, meterInfoList, sourceMonitorInfo)
    }
}


/**
 * 需要展示对sql的监控
 * 项目状态的监控
 */
class ServerMonitorInfo(
        val timerInfoList: ServerTimerInfo? = null,
        val meterInfoList: List<MeterInfo>? = listOf(),
        val sourceMonitorInfo: SourceMonitorInfo? = null
) : MonitorInfo()

class ServerMonitorObj(
) : MonitorObj()
